<?php
require dirname(__FILE__) . "/function_path.php";
require dirname(__FILE__) . "/function_member.php";
require dirname(__FILE__) . "/function_json.php";
require dirname(__FILE__) . "/function_regex.php";
require dirname(__FILE__) . "/function_temple.php";
require dirname(__FILE__) . "/function_resourceupdater.php";
require dirname(__FILE__) . "/function_permission.php";
require dirname(__FILE__) . "/function_home.php";
require dirname(__FILE__) . "/function_parent.php";
require dirname(__FILE__) . "/function_manager.php";
require dirname(__FILE__) . "/function_admin.php";
require dirname(__FILE__) . "/function_question.php";

function getConfig()
{
    global $_GCONFIG;
    return $_GCONFIG;
}

/**
 * 输出debug信息，obj为null或缺省时输出堆栈追溯
 *
 * @param object $obj
 *            信息
 *            
 */
function debug($obj = null)
{
    global $_GCONFIG;
    if ($_GCONFIG["debug"]["state"]) {
        if ($obj == null) {
            $html = "<br />---------DEBUG调试信息 堆栈追溯---------- <br />";
            $i = 0;
            foreach (debug_backtrace() as $row) {
                $i ++;
                $html .= $i . "-| At " . $row['file'] . ':' . $row['line'] . ', function name:' . $row['function'] . "()" . "<br />";
            }
            $html .= "---------------------------------------------- <br />";
            print_r($html);
        }
        print_r($obj);
        echo "<br>";
    }
}

/**
 * 获取客户端IP
 * * @return string 客户端IP
 */
function getIP()
{
    global $ip;
    if (getenv("HTTP_CLIENT_IP"))
        $ip = getenv("HTTP_CLIENT_IP");
    else if (getenv("HTTP_X_FORWARDED_FOR"))
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if (getenv("REMOTE_ADDR"))
        $ip = getenv("REMOTE_ADDR");
    else
        $ip = "Unknow";
    return $ip;
}

function sha256($str = '')
{
    return hash("sha256", $str);
}

/**
 * 返回是否为ajax请求
 *
 * @return boolean 值
 */
function isAjaxRequest()
{
    global $_G;
    if (! isset($_G["ajax"])) {
        $_G["ajax"] = get_get("ajax") != "";
    }
    return $_G["ajax"];
}

/**
 * 读取POST 如果有则返回，没有则返回""
 *
 * @param string $name
 *            name
 */
function get_post($name)
{
    return isset($_POST[$name]) ? $_POST[$name] == "undefined" ? "" : $_POST[$name] : "";
}

/**
 * 读取GET 如果有则返回，没有则返回""
 *
 * @param string $name
 *            name
 */
function get_get($name)
{
    return isset($_GET[$name]) ? $_GET[$name] == "undefined" ? "" : $_GET[$name] : "";
}
/**
 * 轮询GET和POST，检索用户输入，先行查询post
 */
function get_entry($name)
{
    $back = get_post($name);
    if (! $back)
        $back = get_get($name);
    return $back;
}

function addQueryTotal()
{
    global $_G;
    if (isset($_G["queryamount"])) {
        $_G["queryamount"] = $_G["queryamount"] + 1;
    } else {
        $_G["queryamount"] = 1;
    }
}

?>